package daohibernate;

import hibernate.HibernateUtil;

import java.util.List;

import negocio.beans.oficinaventa.Remito;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class RemitoDAO {
	private static RemitoDAO instancia = null;
	private static SessionFactory sf = null;	
	
	public static RemitoDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new RemitoDAO();
		} 
		return instancia;
	}
	
	public void altaRemitos(List<Remito> lista){
		Session s = sf.openSession();
		s.beginTransaction();
		for(Remito elemento:lista){
			s.persist(elemento);
		}
		s.flush();
		s.getTransaction().commit();
	}
	
	public void altaRemito(Remito r){
		System.out.println("Ingresando al DAO alta remito");
		Session s = HibernateUtil.getSessionFactory().openSession();
		s.beginTransaction();
		
		System.out.println("Antes de persist");
		s.persist(r);
		
		s.flush();
		System.out.println("antes de commit");
		s.getTransaction().commit();
		System.out.println("Saliendo del DAO");
	}
}
